package com.tm.d5_stringjoiner;

import java.util.StringJoiner;

/**
 * 2024/5/23 Cjj StringJoiner使用 18：08
 */
public class Test {
    public static void main(String[] args) {
       //目标：掌握StringJoiner的使用
        //StringJoiner joiner = new StringJoiner(",");
        StringJoiner joiner = new StringJoiner(",","[","]");
        joiner.add("小明");
        joiner.add("张三三");

        System.out.println(joiner);

        System.out.println(joiner.length());
        System.out.println(joiner.toString());

        System.out.println(getArrayData(new int[]{17, 18, 19}));

    }

      public static String getArrayData(int[] arr){
         if(arr==null){
             return null;
         }

          StringJoiner joiner = new StringJoiner(",", "[", "]");
          for (int i = 0; i < arr.length; i++) {
              joiner.add(arr[i]+"");
          }
          return joiner.toString();
      }
}
